<?php
class Tourism_goods_brand_model extends CI_Model
{
    private $table   = 'tourism_goods_brand';

    /*
     * 数据数量
     * */
    public function total($param = array())
    {
        $this->db->from($this->table.' as b');
        if (!empty($param['brand_name'])){
            $this->db->like('b.brand_name', trim($param['brand_name']));
        }
        if (!empty($param['class_c'])) {
            $this->db->where('b.category_id', (int)$param['class_c']);
        }
        return $this->db->count_all_results();
    }
    /*
     * 数据列表
     * */
    public function page_list($page_num, $num, $param = array())
    {
        $this->db->from($this->table.' as b');
        if (!empty($param['brand_name'])){
            $this->db->like('b.brand_name', trim($param['brand_name']));
        }
        if (!empty($param['class_c'])) {
            $this->db->where('b.category_id', (int)$param['class_c']);
        }
        $this->db->order_by('b.brand_id', 'DESC');
        $this->db->limit($page_num, $num);
        return $this->db->get();
    }
    /*
     *添加品牌
     * */
    public function addBrand($params)
    {
        $data = array(
            'category_id'   => $params['class_c'],
            'category_name' => $params['category_name'],
            'brand_name'    => $params['brand_name'],
        );
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
   /*
    *更新品牌
    * */
    public function update($postData)
    {
        $data = array(
            'category_id'   => $postData['class_c'],
            'category_name' => $postData['category_name'],
            'brand_name'    => $postData['brand_name'],
        );
        $this->db->where('brand_id', $postData['brand_id']);
        return $this->db->update($this->table, $data);
    }
    
    /*
     *删除品牌
     * */
    public function delete($brand_id)
    {
        $this->db->where('brand_id', $brand_id);
        return $this->db->delete($this->table);
    }
    
    /*
     *根据category_Id 获取品牌信息
     * */
    public function getBrand($cid)
    {
        $this->db->where('category_id', $cid);
        return $this->db->get($this->table);
    }
    
    /*
     *根据brand_Id 获取品牌信息
     * */
    public function getBrandByBrandId($bid)
    {
        $this->db->where('brand_id', $bid);
        return $this->db->get($this->table);
    }

}